# write by hasaki
# first edit on 2019/04/17
# last change on 2019/04/19
# 上传文件到git上
import os
import sys
sys.path.append(os.getcwd())
import time

from hashakisea.engine.log.logSystem import SaveOnGit

def checkTheFile(file_path,global_time):
    '''上传前检查文件'''
    new_check=float(os.path.getmtime(file_path))
    if new_check>global_time[0]:
        print('本地文件已更新,准备上传新文件到git',new_check,'hasaki',global_time[0])
        global_time[0]=new_check
        return 1
    else:
        return 0

def upload(file_path):
    '''上传到git '''
    git=SaveOnGit()
    git.file_path=file_path
    git.saveAsGit()
    print('已上传新文件到git 上')
    
if __name__=='__main__':
    file_path='C:/Users/cchyp/Desktop/hasaki/quote/last_day/quote.jpg'
    local_git='C:/Users/cchyp/Desktop/hasaki'
    global_time= [float(os.path.getmtime(file_path))]
    
    while 1:
        is_new= checkTheFile(file_path,global_time)
        if is_new==1:
            upload(local_git)
        else:
            continue
        time.sleep(10)